<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Kinban"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ViewModels="clr-namespace:Kinban.ViewModels" mc:Ignorable="d" x:Class="Kinban.MainWindow"
        Title="MainWindow" Height="800" Width="1400" Loaded="Window_Loaded" Unloaded="Window_Unloaded"
    WindowState="Maximized"
    WindowStyle="None"
    AllowDrop="True"
    Drop="DropHandler"
    >
    <Window.Resources>
        <ViewModels:MainViewModel x:Key="MainViewModel" />
        <local:PersonConverter x:Key="PersonConverter"/>
        <local:PriorityConverter x:Key="PriorityConverter"/>
        <Style TargetType="{x:Type ListBoxItem}">

            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="Padding" Value="2,0,0,0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Background" Value="Transparent">
                                </Setter>

                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="Selector.IsSelectionActive" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd" Value="Transparent"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

   </Window.Resources>
    <Window.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black"/>
            <GradientStop Color="White" Offset="0.46"/>
            <GradientStop Color="#FF141313" Offset="1"/>
            <GradientStop Color="#FFF9F9F9" Offset="0.15"/>
        </LinearGradientBrush>
    </Window.Background>

    <TabControl Name="MainTab" TabStripPlacement="Bottom" DataContext="{Binding Source={StaticResource MainViewModel}}" Background="Transparent" >
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:1"/>
                </VisualStateGroup.Transitions>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <TabItem Header="Backlog" DataContext="{Binding TfsViewModel}"  >
        </TabItem>

        <TabItem Header="Kinban"  IsSelected="True" DataContext="{Binding TfsViewModel}"  >
            <TabItem.Resources>

                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="FontSize" Value="20" />

                </Style>

                <DataTemplate x:Key="StoryTemplate">
                    <Border AllowDrop="True" Drop="DropHandler" DragOver="DragOverHandler"
                            x:Name="border" Margin="5" Width="235" Height="150" 
                            RenderTransformOrigin="0.5,0.5" 
                            HorizontalAlignment="Center"
                            MouseEnter="border_MouseEnter"
                            MouseLeave="border_MouseLeave" >
                        <Border.Resources >
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Foreground" Value="White" />
                                <Setter Property="Margin" Value="3" />
                                <Setter Property="FontSize" Value="25" />
                                <Setter Property="FontFamily" Value="Agency FB" />                                
                            </Style>

                            <Style x:Key="NormalStory" TargetType="Grid">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ErrorOccurred}" Value="true">
                                        <Setter Property="Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>

                            <Style x:Key="ErrorStory" TargetType="Grid">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ErrorOccurred}" Value="true">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding ErrorOccurred}" Value="false">
                                        <Setter Property="Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>

                        </Border.Resources>

                        <Grid>

                            <Grid Background="{Binding StackRank, Converter={StaticResource PriorityConverter}}" Style="{StaticResource NormalStory}"  >
                                <Grid.RowDefinitions >
                                    <RowDefinition Height="2*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Row="0" Grid.Column="0"  Grid.ColumnSpan="2" TextWrapping="Wrap" Text="{Binding Description}" />
                                <TextBlock Grid.Row="1" Grid.Column="0" TextWrapping="NoWrap" Text="{Binding StartDate}"  VerticalAlignment="Bottom" TextTrimming="CharacterEllipsis"/>
                                <Image Grid.ColumnSpan="2" Grid.RowSpan="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" Source="{Binding AssignedTo, Converter={StaticResource PersonConverter}, ConverterParameter={StaticResource MainViewModel}}" Height="50" />

                            </Grid>

                            <Grid Background="Red" Style="{StaticResource ErrorStory}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <TextBlock Grid.Row="0" Text="Refreshing..." FontWeight="ExtraBold" />
                                <TextBlock Grid.Row="1" Text="{Binding ErrorMessage}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" />
                            </Grid>

                        </Grid>
                    </Border>
                    <DataTemplate.Triggers>
                        <EventTrigger RoutedEvent="FrameworkElement.Loaded"/>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </TabItem.Resources>

            <Grid >

                <Grid.RowDefinitions>
                    <RowDefinition Height="100" />
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="200"/>
                    </Grid.ColumnDefinitions>

                    <StackPanel Grid.Column="0" DataContext="{Binding Source={StaticResource MainViewModel}}">
                        <TextBlock Text="Backlog Count:" Foreground = "White" FontSize="28" TextAlignment="Center" FontFamily="Agency FB">
                        	<TextBlock.TextEffects>
                        		<TextEffect>
                        			<TextEffect.Foreground>
                        				<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        					<GradientStop Color="Black"/>
                        					<GradientStop Color="White" Offset="0.699"/>
                        					<GradientStop Color="#FFA9A6A6" Offset="0.006"/>
                        				</LinearGradientBrush>
                        			</TextEffect.Foreground>
                        		</TextEffect>
                        	</TextBlock.TextEffects></TextBlock>
                        <TextBlock Text="{Binding Backlog}" DataContext="{Binding TfsViewModel}" TextWrapping="Wrap" FontSize="28" TextAlignment="Center" VerticalAlignment="Bottom" FontFamily="Agency FB" Foreground="White"></TextBlock>
                    </StackPanel>
                    <ListBox Name="PeopleList" Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Users}" PreviewMouseLeftButtonDown="MouseDownHandler" Drop="DropHandler" DragOver="DragOverHandler" Background="Transparent">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="80" VerticalAlignment="Center" Margin="0,5">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Border BorderThickness="2" >
                                        <Border.Background>
                                            <RadialGradientBrush>
                                                <GradientStop Color="Black" Offset="0"/>
                                                <GradientStop Color="White" Offset="1"/>
                                            </RadialGradientBrush>
                                        </Border.Background>
                                        <Border.BorderBrush>
                                            <RadialGradientBrush></RadialGradientBrush>
                                        </Border.BorderBrush>

                                        <Image Source="{Binding PictureUrl}" Height="70" Stretch="Uniform"  />
                                    </Border>
                                </Grid>

                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <StackPanel Grid.Column="3" DataContext="{Binding Source={StaticResource MainViewModel}}">
                        <TextBlock Text="Released Count:" Foreground = "White" FontSize="28" TextAlignment="Center" FontFamily="Agency FB"></TextBlock>
                        <TextBlock Text="{Binding Released}" DataContext="{Binding TfsViewModel}" TextWrapping="Wrap" FontSize="28" TextAlignment="Center" VerticalAlignment="Bottom" FontFamily="Agency FB" Foreground="White"></TextBlock>
                    </StackPanel>
                </Grid>
                <Grid Grid.Row="1" Name="QueueGrid" >
                    <Grid.Resources >
                        <Style TargetType="{x:Type ListBox}">
                            <Setter Property="Background" Value="#00B1DE22" />

                        </Style>
                        <Style x:Key="QueueHeader" TargetType="TextBlock">
                            <Setter Property="Foreground" Value="White"></Setter>
                            <Setter Property="FontFamily" Value="Agency FB" />
                            <Setter Property="FontSize" Value="28" />
                            <Setter Property="Margin" Value="10,0,0,0" />
                        </Style>
                    </Grid.Resources>
                    <Grid.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0"/>
                            <GradientStop Color="#FF414040" Offset="1"/>
                        </LinearGradientBrush>
                    </Grid.Background>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="1*" />
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition  />
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Column="0" Text="Project Queue" Style="{StaticResource QueueHeader}"   />
                    <Grid Grid.Column="0" Grid.Row="1" DataContext="{Binding ProjectQueue}" Background="Transparent">
                        <ListBox ItemsSource="{Binding StoriesView, Mode=OneWay}" ItemTemplate="{StaticResource StoryTemplate}" AllowDrop="True" PreviewMouseLeftButtonDown="MouseDownHandler" Drop="DropHandler" DragOver="DragOverHandler" GiveFeedback="GiveFeedback"
                             ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemContainerStyle="{DynamicResource ListBoxItemStyle1}"/>
                    </Grid>

                    <TextBlock Grid.Column="1" Text="Development" Style="{StaticResource QueueHeader}"/>
                    <Grid Grid.Column="1" Grid.Row="2" DataContext="{Binding Development}">
                        <ListBox  ItemsSource="{Binding StoriesView, Mode=OneWay}"  ItemTemplate="{StaticResource StoryTemplate}" AllowDrop="True" PreviewMouseLeftButtonDown="MouseDownHandler" Drop="DropHandler" DragOver="DragOverHandler" GiveFeedback="GiveFeedback" />
                    </Grid>

                    <TextBlock Grid.Column="2" Text="Ready for Test" Style="{StaticResource QueueHeader}"/>
                    <Grid Grid.Column="2" Grid.Row="2" DataContext="{Binding ReadyForTest}">
                        <ListBox ItemsSource="{Binding StoriesView, Mode=OneWay}"  ItemTemplate="{StaticResource StoryTemplate}" AllowDrop="True" PreviewMouseLeftButtonDown="MouseDownHandler" Drop="DropHandler" DragOver="DragOverHandler" GiveFeedback="GiveFeedback" />
                    </Grid>

                    <TextBlock Grid.Column="3" Text="Testing" Style="{StaticResource QueueHeader}"/>
                    <Grid Grid.Column="3" Grid.Row="2" DataContext="{Binding Testing}">
                        <ListBox ItemsSource="{Binding StoriesView, Mode=OneWay}"  ItemTemplate="{StaticResource StoryTemplate}" AllowDrop="True" PreviewMouseLeftButtonDown="MouseDownHandler" Drop="DropHandler" DragOver="DragOverHandler" GiveFeedback="GiveFeedback" />
                    </Grid>

                    <TextBlock Grid.Column="4" Text="Done" Style="{StaticResource QueueHeader}"/>
                    <Grid Grid.Column="4" Grid.Row="2" DataContext="{Binding Done}">
                        <ListBox  ItemsSource="{Binding StoriesView, Mode=OneWay}"  ItemTemplate="{StaticResource StoryTemplate}" AllowDrop="True" PreviewMouseLeftButtonDown="MouseDownHandler" Drop="DropHandler" DragOver="DragOverHandler" GiveFeedback="GiveFeedback" />
                    </Grid>

                </Grid>

                <Grid Grid.Row="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Grid Grid.Column="0">
                        <StackPanel >
                            <TextBlock Text="Description:" FontFamily="Agency FB" FontSize="21.333" Foreground="White"/>
                            <TextBlock Text="{Binding SelectedStory.DescriptionLong}" TextWrapping="Wrap" Height="Auto" />
                        </StackPanel>
                    </Grid>
                    <Grid Grid.Column="1" >
                        <Grid Grid.RowSpan="3" Grid.ColumnSpan="2">
                            
                            <Grid.Resources>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="White"></Setter>
                                    <Setter Property="FontFamily" Value="Agency FB"></Setter>
                                </Style>

                            </Grid.Resources>
                            
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="1*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="1*" />
                            </Grid.RowDefinitions>

                            <Rectangle Grid.Column="0" Grid.Row="0" Height="40" Width="40" Fill="Orange" Margin="5"/>
                            <TextBlock Grid.Column="1" Grid.Row="0" Text="High Priority" VerticalAlignment="Center" FontSize="20"/>
                            <Rectangle Grid.Column="0" Grid.Row="1" Height="40" Width="40" Fill="Green" Margin="5"/>
                            <TextBlock Grid.Column="1" Grid.Row="1" Text="Medium Priority" VerticalAlignment="Center"  FontSize="20"/>
                            <Rectangle Grid.Column="0" Grid.Row="2" Height="40" Width="40" Fill="Blue" Margin="5"/>
                            <TextBlock Grid.Column="1" Grid.Row="2" Text="Low Priority" VerticalAlignment="Center"  FontSize="20"/>

                            <Border Grid.Row="3" Grid.ColumnSpan="2" Margin="5" HorizontalAlignment="Stretch" BorderThickness="2" Height="70" MouseLeftButtonDown="Border_MouseLeftButtonDown" CornerRadius="10" BorderBrush="#FFE81515" Background="Gray">
                                <TextBlock Text="Lock"  FontSize="30" VerticalAlignment="Center" TextAlignment="Center" Name="LockUnlockCtrl" />
                            </Border>

                        </Grid>

                    </Grid>
                    <Image Grid.Column="2" Width="320" Height="240" Source="{Binding DepthImage}" d:LayoutOverrides="GridBox" />
                </Grid>
            </Grid>


        </TabItem>

        <TabItem Header="Released" DataContext="{Binding TfsViewModel}"  >
        </TabItem>
        <TabItem Header="Kinect Diagnose" DataContext="{Binding KinectViewModel}">
            <TabItem.Resources>
                <Style TargetType="{x:Type Label}">
                    <Setter Property="FontSize" Value="30" />
                    <Setter Property="Padding" Value="0,0,10,0" />
                </Style>
                <DataTemplate x:Key="Point3D">
                    <StackPanel Orientation="Horizontal">
                        <Label Content="{Binding X}" />
                        <Label Content=", " />
                        <Label Content="{Binding Y}" />
                        <Label Content=", " />
                        <Label Content="{Binding Z}" />
                    </StackPanel>
                </DataTemplate>
            </TabItem.Resources>
            <Grid x:Name="MainGrid" >

                <Grid.RowDefinitions >
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions >
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <Label Grid.Column="0" Grid.Row="2" Content="MouseDown"/>
                <Label Grid.Column="1" Grid.Row="2" Content="{Binding MouseDown, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="3" Content="Hand Dist"/>
                <Label Grid.Column="1" Grid.Row="3" Content="{Binding HandDistance, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="4" Content="Shoulder Dist"/>
                <Label Grid.Column="1" Grid.Row="4" Content="{Binding ShoulderDistance, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="5" Content="Hand/Shoulder Diff"/>
                <Label Grid.Column="1" Grid.Row="5" Content="{Binding HandShoulderDifference, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="6" Content="FPS"/>
                <Label Grid.Column="1" Grid.Row="6" Content="{Binding FPS, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="7" Content="Information"/>
                <Label Grid.Column="1" Grid.Row="7" Content="{Binding Information, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="8" Content="Live Mouse"/>
                <CheckBox Grid.Column="1" Grid.Row="8" IsChecked="{Binding LiveMouse, Mode=TwoWay}" VerticalAlignment="Center" />

                <Label Grid.Column="0" Grid.Row="9" Content="Distance"/>
                <Label Grid.Column="1" Grid.Row="9" Content="{Binding DistanceFeedback, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="10" Content="Angle"/>
                <Label Grid.Column="1" Grid.Row="10" Content="{Binding Angle, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="11" Content="Velocity"/>
                <Label Grid.Column="1" Grid.Row="11" Content="{Binding Velocity, Mode=OneWay}"/>

                <Label Grid.Column="0" Grid.Row="12" Content="Image"/>
                <Image Grid.Column="1" Grid.Row="12" Width="360" Height="240" Source="{Binding VideoImage}" HorizontalAlignment="Left" />

                <Label Grid.Column="0" Grid.Row="13" Content="Right Hand"/>
                <Label Grid.Column="1" Grid.Row="13" Content="{Binding RightHand, Mode=OneWay}" ContentTemplate="{StaticResource Point3D}"/>

                <Label Grid.Column="0" Grid.Row="14" Content="Right Wrist"/>
                <Label Grid.Column="1" Grid.Row="14" Content="{Binding RightWrist, Mode=OneWay}" ContentTemplate="{StaticResource Point3D}"/>

                <Label Grid.Column="0" Grid.Row="15" Content="Right Foot"/>
                <Label Grid.Column="1" Grid.Row="15" Content="{Binding RightFoot, Mode=OneWay}" ContentTemplate="{StaticResource Point3D}"/>

                <Label Grid.Column="0" Grid.Row="16" Content="Right Hip"/>
                <Label Grid.Column="1" Grid.Row="16" Content="{Binding RightHip, Mode=OneWay}" ContentTemplate="{StaticResource Point3D}"/>

            </Grid>

        </TabItem>
    </TabControl>
</Window>
